﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MediaStockRepository.cs" company="DST Nexdox">
//   Copyright (c) DST Nexdox. All rights reserved.
// </copyright>
// <summary>
//   Defines the MediaStockRepository type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DocProcessingRepository.Repositories
{
  using System;
  using System.Collections.Generic;
  using System.Data.SqlClient;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using DocProcessingRepository.Contexts;
  using DocProcessingRepository.Interfaces;
  using EFRepository;
  using Entities;

  public class MediaStockRepository : BaseEfRepository<MediaStock>, IMediaStockRepository
  {
    public MediaStockRepository(String connectionString)
      : base(new IdentityDb(connectionString))
    {
    }

    public MediaStockEntity GetById(Int32 mediaStockId)
    {
      MediaStockEntity mediaStock =
        this.GetEntityListByStoreProcedure<MediaStockEntity>(
          String.Format("exec GetMediaStockById '{0}'", mediaStockId)).Single();

      return mediaStock;
    }

    public List<MediaStockEntity> GetByMediaDefinition(Int32 mediaDefinitionId)
    {
      List<MediaStockEntity> mediaStock =
        this.GetEntityListByStoreProcedure<MediaStockEntity>(String.Format("exec GetMediaStockByMediaDefinition '{0}'", mediaDefinitionId))
        .ToList();

      return mediaStock;
    }

    public void UpdateStationNumber(Int32 mediaStockId, Int32 stationNumber)
    {
      this.ExecuteStoredProcedure(String.Format("UpdateStationNumber {0}, {1}", mediaStockId, stationNumber));
    }

    public void DeleteMediaStock(Int32 mediaStockId)
    {
      this.ExecuteStoredProcedure(String.Format("DeleteMediaStock {0}", mediaStockId));
    }

    public MediaStockEntity AddMediaStock(Int32 stockId, Int32 mediaDefinitionId, Int32 stationNumber)
    {
      String sql = String.Format("AddMediaStock {0}, {1}, {2}", stockId, mediaDefinitionId, stationNumber);
      MediaStockEntity addedMediaStock = this.GetEntityListByStoreProcedure<MediaStockEntity>(sql).Single();
      return addedMediaStock;
    }
  }
}
